package coin

type BlockChain struct {
	Blocks []*Block
}

// 添加区块到链上
func (bc *BlockChain) AddBlock(data string) {
	preBlock := bc.Blocks[len(bc.Blocks)-1]// 获取前一个区块
	newBlock := NewBlock(data, preBlock.Hash)//创建新区块
	bc.Blocks = append(bc.Blocks, newBlock)// 链接新区块到链上
}
// 创建区块链
func NewBlockChain() *BlockChain {
	return &BlockChain{[]*Block{NewGenesisBlock()}}
}